package com.neuedu.controller.user;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.neuedu.factory.ClassFactory;
import com.neuedu.service.DeptTypeService;
import com.neuedu.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

@WebServlet(name = "QueryUserServlet", urlPatterns = "/his/queryUser")
public class QueryUserServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name");
        String longinname = request.getParameter("longinname");
        name = "%" + name + "%";
        longinname = "%" + longinname + "%";
        Object[] objs = {name, longinname};
        ObjectMapper om = new ObjectMapper();
        UserService dcs = (UserService) ClassFactory.createObj("UserService");
        List<Map<String, Object>> list = dcs.likeQuery(objs);
        String s = om.writeValueAsString(list);
        PrintWriter writer = response.getWriter();
        writer.append(s);
    }
}
